define(['egis'], function (egis) {
    Window.deserializer = Window.deserializer || new egis.core.Deserializer();
    Window.container = Window.container || {};
    dsBridge.register('create_OfflineLayer', function (sourceId, layerId) {
        var layer = new egis.carto.TileLayer({
            "levelShift": 1,
            id: layerId
        });
        Window.container[sourceId] = layer;
    })

    dsBridge.register('OfflineLayer_setSource', function (sourceId, source) {
        var layer = Window.container[sourceId];
        source = JSON.parse(source);
        source.getSourceType = function () {
            return source.sourceType;
        }
        source['tileLoadFunction'] = function (imageTile, src) {
            var image = imageTile.getImage();
            var tileCoord = imageTile.getTileCoord();
            var z = tileCoord[0], x = tileCoord[1], y = -tileCoord[2]-1;
            dsBridge.call("loadTile", [z, x, y], function (source) {
                image.src = src;
                // image.src = 'http://61.183.117.29:18223/wmts?layer=wmts_beijing_vct_4326&tilematrixset=gridset_beijing_4326_0_18&Service=WMTS&Request=GetTile&Version=1.0.0&Format=png&TileMatrix=gridset_beijing_4326_0_18%3A3&TileCol=6&TileRow=4';
            });
        }
        layer.setSource(source);
    })
})